<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>订单中心</title>
	<link rel="stylesheet" href="css/xingchao.css">
    <link rel="stylesheet" href="css/jquery.page.css">
	<link rel="stylesheet" href="css/bootstrap-new.css">
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/layer/layer.js"></script>
    <script type="text/javascript" src="js/jquery.page.js"></script>
</head>
<body style="background: #EFEFEF; ">
<div class="head">
	<div class="w" style="height:50px;">
		<a href="index.html">
			<img src="images/logo.png" alt="" width="150px;">
		</a>
		<ul class="nav r">
	       <li class="cur">
	            <a href="index.html">众源</a>
	            <sub class="sub1"></sub>
	        </li>
	        <li>
	            <a href="ziyuan.html">资源搜索</a>
	            <sub class="sub1"></sub>
	        </li>
	        <li>
	            <a href="jiaocheng.html">使用教程</a>
	            <sub class="sub1"></sub>
	        </li>
	        <li>
	            <a href="page.html">关于我们</a>
	            <sub class="sub1"></sub>
	        </li>
	        <li>
	            <a href="user.html" id="user-box">会员中心</a>|
                <a href="user.html?action=out">退出</a>
	        <sub class="sub1"></sub>
	        </li>
	        <li id="langBox">
                 <a href="javascript:void(0)" data-lang='zh-CN'>中</a>&nbsp;|
                 <a href="javascript:void(0)" data-lang="en-US">EN</a>
                 <sub class="sub1"></sub>
             </li>
		</ul>
	</div>
</div>

<div class="main w">
	<div class="position">
		您当前位置：<a href="">首页</a> > <a href="">订单中心</a>
	</div>
	<div class="user">
		<div class="user_left l">
			<ul class="left_c">
				<div class="left_t">资源管理</div>
				<li><a href="agent.html">我的收藏</a></li>
				<li><a href="uploads.html">我的上传</a>	
                <li><a href="userOrder.html" style="color: #5fadfc;">订单中心</a></li>
				<br><div class="left_t">账号管理</div>
                <li><a href="bill.html">我的余额</a></li>
				<li><a href="editpwd.html">修改密码</a></li>
			</ul>
		</div>
		<div class="user_right r">
			<div class="right_t">订单中心</div>
			<div class="right_c">
				<table class="table table-hover">
					<thead>
						<tr>
							<th>No.</th>
							<th>数据集key</th>
							<th>支付方式</th>
							<th>价格</th>
							<th>订单日期</th>
							<th>订单状态</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody id="orderBody"></tbody>
				</table>
				<div class="clear"></div>
 				<div id="pageNav" data-all="0"></div>
			</div>
		</div>
	</div>
	<div class="clear"></div>
</div>
<div class="copyright"> Copyright @ 2016-2017 蚂蚁金融服务集团  沪ICP备16046581号-1&nbsp;&nbsp;&nbsp;&nbsp;技术支持：星巢网络
</div>
</div>
</body>
</html>
<script type="text/javascript" src="js/App.min.js"></script>
<script type="text/javascript">
$(function(){
	setTimeout(function(){ getOrders(1);},10);
})
var pageConfig ={
		pageSize:5,
		page:1,
	    condition:0
}
function getOrders(page){
	pageConfig.page = page;
    var url = "http://www.usources.cn/api/order/list";
    var loading = layer.msg('正在获取所有订单，请等候...', {icon: 16,time: 999999, shade: [0.3, '#000']});
    $.ajax({
    	url:url+'?'+Math.random(),
    	type:'GET',
    	xhrFields: {
    		withCredentials: true
    	},
    	crossDomain:true,
    	data:{pageNo:pageConfig.page,pageSize:pageConfig.pageSize},
    	success:function(data){
		 layer.close(loading);
		 if(data.code==200){
		 	var listdata = '';
			 for(var i in data.data.list){
				var res = data.data.list[i];
				var statusInt = res.status;
				var status;
				var operationStr;
				var price = res.price + "";
				var priceStr = price + "个众源币";
				var dataKeyInfoPrefix = "";
				var priceTypeStr = "";
				if(res.priceType == 1){
					dataKeyInfoPrefix="<a href='http://www.usources.cn/resource/"+res.dataKey+"' target='_blank'>";
					priceTypeStr = "按条支付";
				}else if(res.priceType == 0){
					dataKeyInfoPrefix="<a href='http://www.usources.cn/ontology/"+res.dataKey+"'  target='_blank'>";
					priceTypeStr = "按Class集支付";
				}else if(res.priceType == -1){
					dataKeyInfoPrefix="<a href='http://www.usources.cn/ontology/"+res.dataKey+"'  target='_blank'>";
					priceTypeStr = "私密数据集上传";
				}
				if(statusInt == 0){
					status = "等待支付";
					var orderIdStr = '"'+res.orderId+'"';
					operationStr = "<a href='javascript:void(0);' onclick='payNow("+orderIdStr+","+res.price+")'>立即支付</a>";
				}else if(statusInt == 1){
					status = "已支付";
					operationStr = dataKeyInfoPrefix + "查看并下载</a>";
				}else if(statusInt == 2){
					status = "已取消"
					operationStr = dataKeyInfoPrefix + "查看数据集</a>";
				}else{
					status = "未知";
				}

				listdata = listdata + "<tr><td>"+(parseInt(i)+1)+
				"</td><td style='width:250px;word-break:break-all;word-wrap:break-word'>"+dataKeyInfoPrefix+
				res.dataKey+"</a></td><td>"+priceTypeStr+"</td><td>"+priceStr+"</td><td>"+res.orderDate+
				"</td><td>"+status+"</td><td>"+operationStr+"</td></tr>";
			}
			$("#orderBody").empty().append(listdata);
			if(pageConfig.condition == 0){
				var rInfo = data.data.info;
			 	var totalSize =  rInfo.hasOwnProperty('totalSize')?rInfo.totalSize:-1;
				var totalPages = $("#pageNav").data('all');
				if(totalSize != -1){
					totalPages = Math.ceil(totalSize/pageConfig.pageSize);
				}
				$("#pageNav").Page({
					totalPages:totalPages,//分页总数
					liNums: 5,//分页的数字按钮数(建议取奇数)
					activeClass: 'activP', //active 类样式定义
					callBack : function(page){
						getOrders(page);
					}
				});
				pageConfig.condition = 1;
			}
		 }else{
		 	if(data.code == 1003){
		 		layer.open({
		 			content: '您尚未登录,请先登录',
		 			btn: ['确认'],
		 			yes: function(index, layero){
		 				location.href="login.html";
		 			},
		 			icon:1});
		 	}else{
		 		layer.msg("获取订单失败!",{icon:2,time:50000});
		 	}
		 }
    	},
    	error:function(data){
    		layer.close(loading);
    		layer.msg("获取订单失败!",{icon:2,time:50000});
    	},dataType:'json'});
}
function payNow(orderId,price){
	$.ajax({
		url:"api/payByZyCoin",
		type:'GET',
		xhrFields: {
			withCredentials: true
		},
		crossDomain:true,
		data:{"price":price,"orderId":orderId},
		success:function(data){
			if(data.code == 1003){
				layer.open({
					content: "您尚未登录"
					,btn: ['确认']
					,yes: function(index, layero){
						location.href="login.html";
					}
				});
			}else if(data.code == 1002){
				layer.msg('参数不全!',{icon:2});
			}else if(data.code == 1014){
				layer.msg('价格字段错误!',{icon:2});
			}else if(data.code == 1013){
				layer.msg('该订单不存在!',{icon:2});
			}else if(data.code == 1015){
				layer.msg('订单状态无效',{icon:2});
			}else if(data.code == 1012){
				layer.msg('余额不足,请先充值!',{icon:2});
			}else if(data.code == 200){
				layer.open({
					content: "支付成功"
					,btn: ['确认']
					,yes: function(index, layero){
						self.location=document.referrer;
					}
				});
			}else{
				layer.msg('服务异常,请稍后重试',{icon:2});
			}
		},
		error:function(error){
			console.log(error);
			layer.msg('服务异常,请稍后重试',{icon:2});
		},dataType:'json'});
}
</script>